package com.css.project.item.controller;

import com.css.common.utils.poi.ExcelUtil;
import com.css.framework.aspectj.lang.annotation.Log;
import com.css.framework.aspectj.lang.enums.BusinessType;
import com.css.framework.web.controller.BaseController;
import com.css.framework.web.domain.AjaxResult;
import com.css.framework.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import   com.css.project.item.domain.ProItem;
import com.css.project.item.domain.ProItemPerson;
import com.css.project.item.domain.ProItemUser;
import   com.css.project.item.service.IProItemService;
import com.css.project.oa.cash.domain.ProCash;
import com.css.project.oa.cash.domain.ProCashItem;

import springfox.documentation.annotations.ApiIgnore;
        
/**
 * 项目信息Controller
 * 
 * @author css
 * @date 2020-05-09
 */
@RestController
@RequestMapping("/item/item")
public class ProItemController extends BaseController
{
    @Autowired
    private IProItemService proItemService;

    /**
     * 查询项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProItem proItem)
    {
        startPage();
        List<ProItem> list = proItemService.selectProItemList(proItem);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProItem proItem)
    {
        List<ProItem> list = proItemService.selectProItemList(proItem);
        ExcelUtil<ProItem> util = new ExcelUtil<ProItem>(ProItem.class);
        return util.exportExcel(list, "item");
    }

    /**
     * 获取项目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put(AjaxResult.DATA_TAG, proItemService.selectProItemById(id));
        ajax.put("itemUserIds", proItemService.selectUserListByItemId(id));
        return ajax;
    }

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProItem proItem)
    {

        return toAjax(proItemService.insertProItem(proItem));
    }

    /**
     * 修改项目信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProItem proItem)
    {

        return toAjax(proItemService.updateProItem(proItem));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proItemService.deleteProItemByIds(ids));
    }
    /**
     * 
    * @Title: selectPersonListByItem 
    * @Description: 获取项目人员
    * @param @param proCash
    * @param @return    设定文件 
    * @author ShiChao 
    * @return TableDataInfo    返回类型 
    * @throws
     */
    @RequestMapping(value = "/selectPersonListByItem/{itemId}", method = RequestMethod.GET)
    public TableDataInfo selectPersonListByItem(@PathVariable("itemId") Long itemId){
        List<ProItemPerson> list = proItemService.getPersonListByItemId(itemId);
        return getDataTable(list);
    }
}
